package jmu.net.chpt03;

public class Person {
	private String name;
	private int age;
	private int gender;
	private int id;
	private static int count;// 类属性

	public static void main(String[] args) {
		Person x1 = new Person("S", 20);
		// System.out.println(x1.getId());
		Person x2 = new Person("B", 22);
		// System.out.println(x2.getId());
		// System.out.println("count="+Person.getCount());
		// for(int i =1; i<10;i++){
		// System.out.println(new Person());
		//
		// }
		// System.out.println("count="+Person.getCount());
		System.out.println(x1.equals(x2));

	}

	public Person() {
	}

	public static int getCount() {
		return count;
	}

	{
		id = count;
		count++;
	}

	@Override
	public String toString() {
		return "Person [name=" + name + ", age=" + age + ", gender=" + gender + ", id=" + id + "]";
	}

	public Person(String name, int age) {

		this.name = name;
		this.age = age;
	}

	public Person(String name, int age, int gender) {
		this(name, age);
		this.gender = gender;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public int getId() {
		return id;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (age != other.age)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

}
